package com.paperobot.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.paperobot.dao.PaperDao;
import com.paperobot.model.Paper;

@Repository("paperService")
public class PaperServiceImpl implements PaperService{
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	private PaperDao  paperDao;

	@Resource
	public void setPaperDao(PaperDao paperDao) {
		this.paperDao = paperDao;
	}

	public Long addPaper(Paper paper) {
		try {
			return paperDao.addPaper(paper);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1L;
	}

	public Paper getPaper(Long paperId){
		Paper paper = null;
		try {
			paper = paperDao.getPaper(paperId);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return paper;
	}

	public int updatePaper(Paper paper) {
	
		try {
			return paperDao.updatePaper(paper);
		} catch (Exception e) {
			logger.info(e.getMessage());
		}
		return -1;
	}

	public List<Paper> getPaperList(int type, boolean status) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("status", status?1:0);
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

	public List<Paper> getPaperList(int type, int subType, boolean status) {
		List<Paper> paperList = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		map.put("subType", type);
		map.put("status", status?1:0);
		
		try {
			paperList = paperDao.getPaperList(map);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return paperList;
	}

}












